home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2920 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.7 KB  |  79 lines

  1. Path: watnews.watson.ibm.com!usenet
  2. From: "John D. Prokopek" <jprok@watson.ibm.com>
  3. Newsgroups: comp.os.ms-windows.programmer.ole,comp.lang.c++
  4. Subject: Re: Problems VC++4.0 & StringFromCLSID function
  5. Date: Sat, 20 Jan 1996 09:54:23 -0800
  6. Organization: IBM T.J. Watson Research Center
  7. Message-ID: <31012C4F.10CC@watson.ibm.com>
  8. References: <4djn2d$mps@earth.superlink.net>
  9. NNTP-Posting-Host: internet-gw.watson.ibm.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b3 (Win95; I)
  14.  
  15. Ananda Subramaniam wrote:
  16. > Hi,
  17. > I have an OLE sample that I wrote and compiled in VC++ 2.0 without any problems.
  18. > However, when I tried to compile in VC++ 4.0, I had trouble with the
  19. > StringFromCLSID function.
  20. > I get a message "cannot convert 2nd parameter char ** to unsigned short**"
  21. > The Prototype for StringFromCLSID is:
  22. > StringFromCLSID(REFCLSID, LPOLESTR *);
  23. > I am passing as my second parameter a LPSTR *, which shouldn't be a problem
  24. > because grepping through the several include files provided by MS there is a
  25. > typedef as follows
  26. > typedef LPSTR LPOLESTR;
  27. > The compiler seems to think that LPOLESTR is of type unsigned short.
  28. > To further confirm this, I changed the type of my string to LPOLESTR and the
  29. > compiler went past StringFromCLSID function but complained on the next line
  30. > where I had AfxMessageBox(mystr).  The compiler said "non of the 2 overloads can
  31. > covert parameter one from type unsigned short * "
  32. > After this, I went and modified the header file that has the prototype for
  33. > StringFromCLSID (objbase.h) and modified the prototype from LPOLESTR to LPSTR
  34. > and the app compiled and sort of worked.
  35. > I am running out of ideas, plus it does not help being the only C++ programmer
  36. > in the office.   Any help will be appreciated.
  37. > Ananda
  38. > email: ananda@mars.superlink.net
  39.  
  40. This little problem bugged me too.
  41. There is an easy way to convert- 
  42. If you include afxpriv.h there are conversion macros that will allocate 
  43. memory perform the necessary conversion and return the proper pointer.
  44.  
  45. here is a little sample from my junk...
  46.  
  47. #include "afxpriv.h"
  48.  
  49. void CBaseObjectApp::RegisterServer(void)
  50. {
  51.     OLECHAR     szID[128];
  52.     TCHAR       szCLSID[128];
  53.     TCHAR       szModule[512];
  54.     USES_CONVERSION;            << this initializes some vars
  55.  
  56.     StringFromGUID2(CLSID_ChatSrv, (LPOLESTR)szID, 128); << LPOLESTR is 
  57. what is expected
  58.     lstrcpy(szCLSID, TEXT("CLSID\\"));
  59.     lstrcat(szCLSID, OLE2CT(szID));     << OLE2CT performs a conversion
  60.                     << and returns the correct 
  61.                     << pointer
  62.                     << check it out
  63. I still need to compile with MBCS and have had no luck compileing with
  64. _UNICODE defined but that is another headache.
  65. Microsoft - "Do it our way until we tell you otherwise"
  66.  
  67. later 
  68. johnp
  69.